<?php
namespace Home\Controller;
use Think\Controller;
use Home\Model\SqliteStainfo;
class ApwifidataController extends BaseController {
    public function apwifidata(){
        $sqlitestainfo=new SqliteStainfo();
        $stadata= $sqlitestainfo->select();

        $stainfodatable= D('Stainfo');
        $stainfodatable->where(1)->delete();
        $count=count($stadata);
        if($stadata){
            for($iloop=0; $iloop < $count; $iloop++){
                $map[$iloop]= array(
                    'requsetssid'=>$stadata[$iloop]['essid'],
                    'smac'=>$stadata[$iloop]['s_mac'],
                    'imac'=>$stadata[$iloop]['b_mac'],
                    'dmac'=>$stadata[$iloop]['d_mac'],
                    'time'=>$stadata[$iloop]['time'],
                    'encryption'=>$stadata[$iloop]['en_mode'],
                    'signalstrength'=>$stadata[$iloop]['signal'],
                    'devname'=>$stadata[$iloop]['device_name'],
                );
            }
        }
        if($count){
            $stainfodatable->addAll($map);
        }


        $stainfodata = $stainfodatable->order(array( 'time'=>'desc'))->select();
        if($stainfodata==true){
            $this->assign("scanterminaldata",$stainfodata);
        }




        $this->display();
        return;

        //获取热点和终端列表
        $url=$_SESSION['cardinfo'][self::$cardtype_scan]['cardip'] . C('LUCI_WIFISCAN_URL') . 'TerminalDevInfo/nil%20nil%20nil%20nil%20nil%20';
        //var_dump($url);

        $retteerminaldata = http_post_json($url, null);
        //$retteerminaldata = iconv('UTF-8', 'UTF-8//IGNORE', utf8_encode($retteerminaldata));
        $jsterminaldata = json_decode($retteerminaldata,TRUE);

        if($jsterminaldata){
            for($iloop=0; $iloop < count($jsterminaldata[0]); $iloop++){
                $map= array(
                    'requsetssid'=>$jsterminaldata[0][$iloop]['requsetSSID'],
                    'smac'=>$jsterminaldata[0][$iloop]['smac'],
                    'imac'=>$jsterminaldata[0][$iloop]['imac'],
                    'dmac'=>$jsterminaldata[0][$iloop]['dmac'],
                    'time'=>$jsterminaldata[0][$iloop]['time'],
                    'encryption'=>$jsterminaldata[0][$iloop]['encryption'],
                    'signalstrength'=>$jsterminaldata[0][$iloop]['signalStrength'],
                    'devname'=>$jsterminaldata[0][$iloop]['devName'],
                );
                //先查询是否存在相同ssid名称，相同mac
                if(D('Stainfo')->getSimCount( $jsterminaldata[0][$iloop]['smac'])<=0){
                    D('Stainfo')->add($map);
                }
                else{
                    D('Stainfo')->where(array('smac'=>$map['smac']))->save($map);
                }
            }
        }

        $stainfodata = D('Stainfo')->order(array( 'time'=>'desc'))->select();
        if($stainfodata==true){
            $this->assign("scanterminaldata",$stainfodata);
        }

        


        $this->display();
    }
}